﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Thrift.Protocol;
using Thrift.Transport;

namespace ThriftTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }


        private TStreamTransport GetTSocket()
        {
            return new TStreamTransport();
        }
        struct UserProfile
        {
            int id,
       string name,
       string blurb
}
        service UserStorage
        {
        void store(1: UserProfile user), 
        UserProfile getUser(1: i32 uid)
}
    class HelloWorldServiceClient
    {
        public const string SERVERIP = "172.16.61.66";
        public static int SERVERPORT = 9090;
        public static int TIMEOUT = 5000;


        public void startClient(String username)
        {
            TTransport transport = null;
            try
            {
                transport = new TSocket(SERVERIP, SERVERPORT, TIMEOUT);
                //协议要和服务端一致
                TProtocol protocol = new TBinaryProtocol(transport);
                UserStorage.Client client = new UserStorage.Client(protocol);
                transport.Open();

                UserProfile user = new UserProfile();
                user.Id = 1;
                user.Name = "liqb";
                user.Blurb = "aaaaaa";
                client.store(user);
                UserProfile user2;


                user2 = client.getUser(1);
                Console.WriteLine("Thrift client result =: ");

            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
            }
            finally
            {
                if (null != transport)
                {
                    //close
                    transport.Close();
                }
            }
        }
    }
    private void button1_Click(object sender, EventArgs e)
    {
        using (TBufferedTransport transport = new TBufferedTransport(GetTSocket()))
        {
            try
            {
                transport.Open();
                TProtocol protocol = new TBinaryProtocol(transport);
                //CityService.Client client = new CityService.Client(protocol);
                //return func(client);
                //return "";
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                //return "fales:" + e.Message;
            }
            finally
            {
                transport.Close();
            }
        }
    }
}
}
